from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text
from sqlalchemy.orm import declarative_base
from datetime import datetime, timezone

Base = declarative_base()

class Account(Base):
    __tablename__ = 'accounts'
    id = Column(Integer, primary_key=True)
    email = Column(String, unique=True, nullable=False, index=True)
    username = Column(String, nullable=False, index=True)
    password = Column(String, nullable=False)
    invite_code = Column(String)
    # Status: 'pending', 'success', 'fail', 'used'
    status = Column(String, default="pending", nullable=False, index=True)
    # is_deleted: True for soft delete
    is_deleted = Column(Boolean, default=False, nullable=False, index=True)
    reg_time = Column(DateTime, default=lambda: datetime.now(timezone.utc))
    # Store error messages for failed registrations
    err_msg = Column(Text, nullable=True)

    def __repr__(self):
        return f"<Account(id={self.id}, username='{self.username}', email='{self.email}', status='{self.status}')>"